<?php
namespace Cmf\Models;

class Log extends \Phalcon\Mvc\Model
{
	public $user_id;
	public $user_ip;
	public $controller;
	public $action;
	public $model;
	public $record_id;
	public $remark;
	public $created_at;

	public function initialize()
	{
		$this->setSource(TABLE_PREFIX."log");
	}

	static public function createLogRecord($identity,$controller,$action,$model,$record_id)
	{
		$log = new self();
		$log->user_id = $identity['user_id'];
		$log->user_ip = $identity['user_ip'];
		$log->controller = $controller;
		$log->action = $action;
		$log->model = $model;
		$log->record_id = $record_id;
		$log->created_at = time();
		$log->remark = '用户'.$identity['user_name'].'在'.date('Y年m月d日H点:i分').'访问了'
			.$controller.'控制器，执行了'.$action.'方法，'
			.'影响了'.$model.'表,id='.$record_id.'的数据';

		if($log->create()) {

			return true;
		}

		return false;
	}
}
